/**
 * Created by qiao on 2017/6/18.
 */

var baseUrl = "http://wx2.hsxyedu.com";
// var baseUrl = "http://pay.capsui.com";
var $html = '<div id="dstip" style="width: 240px;height: 330px;display: none">' +
    '<div style="width: 100%;text-align: center;padding-top: 10px">微信扫码支付</div>' +
    '<div id="qrcode" style="padding: 20px;"></div>' +
    '<span style="margin-left: 20px">金额:' +
    '<input type="number" value="2" style="width: 120px;height: 29px;border: 1px solid #e3e3e3;" maxlength="4" onkeyup="refresh(this.value)">元' +
    '</span></div>';
var $body = $('body');
$body.append($html);
var qrcode;
jQuery.getScript(baseUrl + "/js/qrcode.min.js").done(function () {
      qrcode = new QRCode(document.getElementById("qrcode"), {
        width: 200,
        height: 200
    });
    qrcode.makeCode("weixin://wxpay/bizpayurl?sign=D0A736528D6C4C3273BDDD1737BD0460&appid=wxc76382e21021363b&mch_id=1350385701&product_id=2&time_stamp=1497696103&nonce_str=B8BF0D48FF104FBE9150E9305731DCA3");
})


// var layerJs = $('<script src="'+ baseUrl +'/js/layer/layer.js"></script>');
// var qrcodeJs = $('<script src="'+ baseUrl +'/js/qrcode.min.js"></script>');
// var $head = $('head');

// $head.append(layerJs);
// $head.append(qrcodeJs);
function show() {
    layer.open({
        type: 1,
        title: false,
        closeBtn: 0, //不显示关闭按钮
        shadeClose: true, //开启遮罩关闭
        content: $('#dstip')
    });
}

function refresh(amount) {
    if (amount < 1) {
        layer.msg('最低1元');
        return;
    }
    $.ajax({
        type: 'GET',
        dataType: "jsonp",
        url: baseUrl+ "/jianpay/scanCodeUrl.do?productId=" + amount,
        jsonp: "callback",
        data: '',
        success: function (data) {
        },
        error: function (xhr) {
        }
    });
}

function callback(obj) {
    qrcode.makeCode(obj.url);
}
